<?php
/**
 * @file FeatureController.php
 * @author LinLin
 * @date 2016年9月13日 下午2:42:07
 * @brief 标签列表页右侧专题
 */
namespace haibao\cms\business\control\pc\common;

use haibao\frame\Environment;
use \haibao\cms\web\common\ftp;


class FeatureController extends \haibao\cms\business\control\pc\channel\ChannelController{

    public function __construct($updateTime = null,$controlId = '',$isPublish = ''){
        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        //推荐专题
//         $exclusiveSerial = array(
//             'stars'=>array(
//                 'exclusive'=>array(22,31),//剧好看  红毯点播台
//                 'column'=>array()
//             ),
//             'fashion'=>array(
//                 'exclusive'=>array(21,36,43),//摩豆  搭配速成班  恋舞趣
//                 'column'=>array(12204)//报君潮流眼
//             ),
//             'beauty'=>array(
//                 'exclusive'=>array(35,44,37,38,45),//美容BANG 街拍时妆  海报口碑评测 新品见报  报告老师
//                 'column'=>array()//
//             ),
//             'jewelrywatch'=>array(
//                 'exclusive'=>array(29,20),//明星珠宝个人秀  每周必buy
//                 'column'=>array()//
//             )
//         );
        $feature = $exclusiveSerial = array();
        $exclusive = \haibao\cms\business\control\FeatureController::getFeatureSerialArray();
        if($exclusive){
            foreach($exclusive as $key=>$exclusiveVal){
                if(isset($exclusiveVal['children']) && !empty($exclusiveVal['children'])){
                    foreach($exclusiveVal['children'] as $k=>$val){
                        $feature[$exclusiveVal['Id']][] = $val['Id'];
                    }
                }
            }
        }
        if($feature){
            foreach($feature as $typeId=>$serialId){
                if($typeId == 47){//明星  配饰  珠宝
                    $exclusiveSerial['stars']['exclusive'] = $feature[$typeId];
                    $exclusiveSerial['stars']['column'] = array();
                }
                if($typeId == 48){//时装  品牌  生活  新娘
                    $exclusiveSerial['fashion']['exclusive'] = $feature[$typeId];
                    $exclusiveSerial['fashion']['column'] = array();
                }
                if($typeId == 49){//美容
                    $exclusiveSerial['beauty']['exclusive'] = $feature[$typeId];
                    $exclusiveSerial['beauty']['column'] = array();
                }
            }
        }
        
        $exclusiveInfo = $exclusive = array();
        $exclusiveInfo[1383] = $exclusiveInfo[7455] = $exclusiveInfo[6863] = $this->getExclusive($exclusiveSerial['stars']['exclusive'],$exclusiveSerial['stars']['column']);
        $exclusiveInfo[310]  = $exclusiveInfo[955] = $exclusiveInfo[520] = $exclusiveInfo[211] = $exclusiveInfo[6] = $exclusiveInfo[0] = $this->getExclusive($exclusiveSerial['fashion']['exclusive'],$exclusiveSerial['fashion']['column']);
        $exclusiveInfo[24] = $this->getExclusive($exclusiveSerial['beauty']['exclusive'],$exclusiveSerial['beauty']['column']);
        if($exclusiveInfo){
            foreach($exclusiveInfo as $key=>$val){
                $fans = array();
                foreach ($val as $info) {
                    $fans[] = $info['ListTime'];
                }
                array_multisort($fans, SORT_DESC, $val);
                $exclusive[$key] = $val;
            }
        }
        //$file= 'D:\code\php\www\trunk\sites\html\diytaghtml\feature.php';
        //$file = '/data/web/www/trunk/sites/html/diytaghtml/feature.php';
        $text = '<?php '."\n".'$feature = '.var_export($exclusive,true).';';
        $this->assign('text', $text);
        $isNewHtml = $this->generateHtml($path,$content);
        $content = $this->getHtml($path);
        $content = $this->replaceCDNLink($content);
        return $content;
    }
    
    //获取各频道专题数据
    private function getExclusive($serialIds,$columIds){
        $exclusive = $columList = $column = $featureList = $featureListAll = array();
        if($serialIds){
            foreach($serialIds as $serialId){
                $featureList = \haibao\cms\business\control\FeatureController::getserialInfoById($serialId);
                if($featureList){
                    $featureListAll[] = $featureList[0];
                }
            }
        }
        if($featureListAll){
            foreach($featureListAll as $key=>$val){
                $exclu['FeatureName'] = $val->FeatureDefine->FeatureName;
                $exclu['Url'] = $val->Url;
                $exclu['ImageUrl'] = $this->getImageLink($val->Image->Filename,300,225,100,0);
                $exclu['ListTime'] = $val->ListTime->format('Y-m-d H:i:s');
                $exclusive[] = $exclu;
            }
        }
        return  $exclusive;
    }
}